<template>
  <div class="xiecheng">
    <div class="admin_main_block">
      <div class="admin_main_block_top">
        <div class="admin_main_block_right">
          <div>
            <el-button
              v-if="isAuth('module:education:course:unit:point:homework:delete')"
              type="danger"
              icon="Delete"
              @click="deleteHandle()">
              {{ i18n('common.batch_delete') }}
            </el-button>
          </div>
          <div class="mr10">
            <el-button icon="Back" @click="router.push({ name: 'module_education_course_unit_point_list', query: {course_id: dataForm.course_id, unit_id: dataForm.unit_id, point_id: dataForm.point_id} })">
              {{ $t('common.return') }}
            </el-button>
          </div>
        </div>
      </div>

      <div class="admin_main_block_top">
        <div class="admin_main_block_select">
          <div class="input">
            <el-select
              v-model="dataForm.organization_id"
              :placeholder="i18n('common.please_select') + i18n('organization.title')"
              clearable>
              <el-option :label="i18n('common.all')" value=""></el-option>
              <el-option v-for="(v, k) in organizationList" :label="v.title" :key="k" :value="v.id">
              </el-option>
            </el-select>
          </div>
          <div class="input">
            <el-input v-model="dataForm.title" :placeholder="$t('common.please_input') + $t('course.unit.point.homework.title')" clearable>
            </el-input>
          </div>
          <div class="input">
            <el-date-picker v-model="dataForm.create_time" type="daterange" :range-separator="i18n('common.to')" :start-placeholder="i18n('common.start_time')" :end-placeholder="i18n('common.end_time')" clearable></el-date-picker>
          </div>
          <div class="input">
            <el-button icon="Search" @click="getDataList(true)">
              {{ i18n('common.search') }}
            </el-button>
          </div>
        </div>
      </div>
      <div class="admin_table_main">
        <el-table :data="dataList" v-loading="dataListLoading" @selection-change="selectionChangeHandle">
          <el-table-column type="selection" header-align="center" align="center">
          </el-table-column>

          <el-table-column prop="id" :label="i18n('common.id')" width="70">
          </el-table-column>

          <el-table-column :label="$t('organization.title')" width="240">
            <template v-slot="scope">
              <span v-if="scope.row.organization">{{ scope.row.organization.title }}</span>
            </template>
          </el-table-column>

          <el-table-column :label="$t('course.title')" width="240">
            <template v-slot="scope">
              <span v-if="scope.row.course">{{ scope.row.course.title }}</span>
            </template>
          </el-table-column>

          <el-table-column :label="$t('course.unit.point.title')" width="140">
            <template v-slot="scope">
              <span v-if="scope.row.point">{{ scope.row.point.title }}</span>
            </template>
          </el-table-column>

          <el-table-column prop="title" :label="$t('course.unit.point.homework.title')">
          </el-table-column>

          <el-table-column prop="sort" :label="i18n('common.sort')" width="80">
          </el-table-column>

          <el-table-column prop="create_time" :label="i18n('common.create_time')" width="160">
          </el-table-column>

          <el-table-column :label="i18n('common.handle')" fixed="right" width="200">
            <template v-slot="scope">
              <el-button
                v-if="isAuth('module:education:course:unit:point:homework:view')"
                type="info"
                icon="View"
                @click="router.push({ name: 'module_education_course_unit_point_homework_view', query: { course_id: dataForm.course_id, unit_id: dataForm.unit_id, point_id: dataForm.point_id, id: scope.row.id } })">
                {{ i18n('common.view') }}
              </el-button>

              <el-button
                v-if="isAuth('module:education:course:unit:point:homework:delete')"
                type="danger"
                icon="Delete"
                @click="deleteHandle(scope.row.id)">
                {{ i18n('common.delete') }}
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="admin_table_main_pagination">
          <el-pagination
            @size-change="sizeChangeHandle"
            @current-change="currentChangeHandle"
            :page-size="pageSize"
            :total="totalPage"
            :current-page="pageIndex"
            background
            layout="prev, pager, next,jumper,total">
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup name="course-unit-point-homework-list">
  import { useBase } from "@/hooks/base/useBase"
  import { useTable } from "@/hooks/table/useTable"

  const { router, query, i18n, isAuth } = useBase()

  const model = ref('education/course/unit/point/homework')

  const organizationList = ref([])

  const dataForm = reactive([
    'organization_id',
    'course_id',
    'unit_id',
    'point_id',
    'title',
    'create_time',
  ])

  const {
    dataList,
    pageIndex,
    pageSize,
    totalPage,
    dataListLoading,
    sizeChangeHandle,
    currentChangeHandle,
    selectionChangeHandle,
    getDataList,
    handleStatus,
    deleteHandle,
  } = useTable(model.value, dataForm)

  const loadOrganizationListList = () => {
    $http({
      url: $http.adornUrl('/organization/select'),
      method: 'get',
    }).then(({ data }) => {
      if (data && data.status === 200) {
        organizationList.value = data.data
      } else {
        $message.error(i18n(data.message))
      }
    })
  }

  onMounted(() => {
    dataForm.course_id = query.course_id
    dataForm.unit_id = query.unit_id
    dataForm.point_id = query.point_id

    getDataList(model)

    loadOrganizationListList()
  })
</script>
